import request from "@/utils/request";
import type {
  AddUserApiParams,
  GetUserListApiParams,
  GetUserListApiResponse,
  GetRoleListsApiResponse,
} from "./model/userModel";

enum api {
  getUserList = "/admin/acl/user",
  updateUser = "/admin/acl/user/update",
  addUser = "/admin/acl/user/save",
  removeUser = "/admin/acl/user/remove",
  getRoleLists = "/admin/acl/user/toAssign",
  userDoAssign = "/admin/acl/user/doAssign",
}
/**
 * 分配角色的请求
 * @param userId 用户id
 * @param roleId 角色列表
 * @returns null
 */
export const userDoAssignApi = (userId: string, roleId: string[]) => {
  return request.post<any, null>(
    api.userDoAssign,
    {},
    {
      params: {
        userId,
        roleId: roleId.join(","),
      },
    }
  );
};

/**
 * 获取角色数据的请求
 * @param id userId
 * @returns GetRoleListsApiResponse
 */
export const getRoleListsApi = (id: string) => {
  return request.get<any, GetRoleListsApiResponse>(api.getRoleLists + `/${id}`);
};
/**
 * 获取用户列表的请求
 * @param GetUserListApiParams
 * @returns
 */
export const getUserListApi = ({
  page,
  limit,
  username,
}: GetUserListApiParams) => {
  return request.get<any, GetUserListApiResponse>(
    api.getUserList + `/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};
/**
 * 添加用户的请求
 * @param data AddUserApiParams
 * @returns null
 */
export const addUserApi = (data: AddUserApiParams) => {
  return request.post<any, null>(api.addUser, data);
};
/**
 * 修改用户的请求
 * @param data AddUserApiParams
 * @returns null
 */
export const updateUserApi = (data: AddUserApiParams) => {
  return request.put<any, null>(api.updateUser, data);
};
/**
 * 删除用户的请求
 * @param id
 * @returns null
 */
export const removeUserApi = (id: string) => {
  return request.delete<any, null>(api.removeUser + `/${id}`);
};
